﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Soft
{

    /// <summary>
    /// 封装方法调用的信息
    /// </summary>
    [Serializable]
    public struct MethodCallInfo
    {

        /// <summary>
        /// 方法名
        /// </summary>
        public string MethodName { get; set; }


        /// <summary>
        /// 方法说明
        /// </summary>
        public string Explain { get; set; }


        /// <summary>
        /// 返回值类型
        /// </summary>
        public Type ReturnType { get; set; }


        /// <summary>
        /// 是否有参数
        /// </summary>
        public bool HasParamster { get; set; }


        /// <summary>
        /// 方法列表
        /// </summary>
        public List<ParameterInfo> MethodParamsterInfoList { get; set; }


        /// <summary>
        /// 封装方法调用的信息  
        /// </summary>
        /// <param name="name">方法名</param>
        /// <param name="explain">方法说明</param>
        /// <param name="returnType">返回值类型</param>
        /// <param name="hasParamster">是否有参数</param>
        /// <param name="methodParamsterInfo">方法参数列表</param>
        public MethodCallInfo(string name, string explain, Type returnType, bool hasParamster, params ParameterInfo[] methodParamsterInfo)
        {
            this.MethodName = name;
            this.Explain = explain;
            this.ReturnType = returnType;
            this.HasParamster = hasParamster;
            this.MethodParamsterInfoList = new List<ParameterInfo>();
            if (methodParamsterInfo != null)
            {
                for (int i = 0; i < methodParamsterInfo.Length; i++)
                {
                    ParameterInfo item = methodParamsterInfo[i];
                    if (this.MethodParamsterInfoList.Exists((ParameterInfo e) => item.Name == e.Name))
                    {
                        throw new Exception("参数“" + item.Name + "”信息已经存在。");
                    }
                    this.MethodParamsterInfoList.Add(item);
                }
            }
        }



    }
}
